<?php

require_once 'Pipes/FileSystem/File/Finder.php';
require_once 'PipesImpl/Config.php';

class Pipes_FileSystem_File_Finder_AllProjects
{
	private $_projects = array();

	public function __construct(PipesImpl_Config $config) {
		$this->_projects = array_reverse($config->projects);
	}

	public function find($name) {
		$finder = new Pipes_FileSystem_File_Finder();
		foreach ($this->_projects as $project) {
			try {
				$file = $finder->find("{$project}/{$name}");
				return $file;
			} catch (Pipes_Exception $e) {

			}
		}

		throw new Pipes_Exception("unable to find [{$name}] in any project");
	}
}
